package com.gedi.data.partition;

import com.gedi.data.bigter.WordConfigApplication;
import com.gedi.data.bigter.maperr.MapperDemo;
import com.gedi.data.bigter.preduce.MyPreduce;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;

import java.io.IOException;

/**
 * @Author:RenPu
 * @Date: 2020/1/19 17:46
 * @Version: 1.0
 * @description:
 */
public class PersonClientApplication {

    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {

        //1:创建mapreduce任务对象

        Configuration conf = new Configuration();
        String jobName="personCount";
        Job job = Job.getInstance(conf, jobName);
        job.setJarByClass(WordConfigApplication.class);

        //2：设置计算数据的输入格式以及输出格式（文本）
        job.setInputFormatClass(TextInputFormat.class);
        job.setOutputFormatClass(TextOutputFormat.class);

        //3：指定数据来源的位置以及结果输出的位置
        //本地数据读取，以及输出位置也在本地，路径需加 file:///
        TextInputFormat.addInputPath(job,new Path("file:///d:\\personcount.txt"));
        //输出的目录必须不存在
        TextOutputFormat.setOutputPath(job,new Path("file:///d:\\personcount"));

        //4：指定mapreduce的mapper阶段和preduce阶段
        job.setMapperClass(PersonMapper.class);
        job.setReducerClass(PersonReduce.class);

        //设置自定义分区器
        job.setPartitionerClass(CustmPartition.class);


        //设置mapreduce的任务个数，默认生成一个mapreduce任务（同理输出的结果文件只有一个）
        job.setNumReduceTasks(5);
        //5:设置mapper和reduce阶段keyout和valueout的类型
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(LongWritable.class);
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(LongWritable.class);

        //6：任务提交
        job.waitForCompletion(true);//输出打印日志





    }





}
